<%@ page language="Java" import="java.util.*,descriptor.*,cv.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%
	OfferListDescriptor offerList = (OfferListDescriptor)request.getAttribute("offerList");
	OfferListDescriptor persoOfferList = (OfferListDescriptor)request.getAttribute("persoOfferList");
	String error1 = (String)request.getAttribute("error1");
%>

<%	
	String notif = "";
	if(error1 != null)
	{
		notif = "<p style=\"color:red; font-size: 10px;\">" + error1 + "<p>";
	}
%>

<html>
	<jsp:include page="StudentHeader.jsp" >
		<jsp:param name="pageTitle" value="Work Placement Management System - Student" />
	</jsp:include>
	<body OnLoad="showmenu(document.getElementById('smenu6'));">
		<jsp:include page="StudentPageHeader.jsp"></jsp:include>
		<div id="container">
			<jsp:include page="StudentMenu.jsp" ></jsp:include>
			<div id="content">
				<h3 class="posttitle">Student - General Offers</h3>
				<div class="entry">
					<%= notif %>
					<p>Find Offer by:</p>
					<br>
					<form name="frmFindOffersBy" method="post" style="margin-left: auto; margin-right: auto;">
						<input type="hidden" name="action" value="offerBy"> 
						<select OnChange="document.frmFindOffersBy.submit();" name="searchtype">  
							<option value="0">Select a search type:</option>	
							<option value="1">All offers</option> 
							<option value="2">Favourite Companies Offers</option>  
						</select>
					</form>
					<br>
					<hr>
					<br>
					<%
							int sizeList = offerList.sizeOfferList(); 
							if(sizeList>0)
							{
					%>
					<table rules="all">
						<thead>
							<tr><th>Offer</th><th>Company</th><th>Expiry Date</th><th>Description</th><th>Action</th></tr>
						</thead>
					<%
								for(int i=0; i<sizeList; i++)
								{	
									int id = offerList.getOfferList().get(i).getId();
									String offer = offerList.getOfferList().get(i).getName();
									String company = offerList.getOfferList().get(i).getCompany();
									String expiry = offerList.getOfferList().get(i).getDateOfEnd();
									String description = offerList.getOfferList().get(i).getDescription();
									String style = "";
									
									boolean applied = false;
									if(persoOfferList != null)
									{
										for(int j=0; j<persoOfferList.sizeOfferList(); j++)
										{
											
											int appliedID = persoOfferList.getOfferList().get(j).getId();
											if(id == appliedID )
											{	
												style = "style=\"background-color: #66ee00;\"";
												applied = true;
											}
										}
									}
										
					%>
						<tr <%= style %>>
							<td><%= offer %></td>
							<td><%= company %></td>
							<td><%= expiry %></td>
							<td><%= description %></td>
					<%
									if(!applied)
									{
					%>
							<td>
								<form name="apply<%= i %>" method="post">
									<input type="hidden" name="action" value="applyOffer">
									<input type="hidden" name="offerID" value="<%= id %>">     
								</form> 
								<a href="javascript:document.apply<%= i %>.submit();" title="Apply to Offer: <%=  offer %>">Apply</a>
							</td>
					<%
									}
									else
									{
					%>
								<td>Already applied</td>
					<%
									}
					%>
						</tr>
				<%
								}
							}
				%>
					</table>
				</div>
	    	</div>
			<jsp:include page="StudentPageFooter.jsp"></jsp:include>
		</div>
	</body>
</html>